package com.lmt.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Date 2018/06/28
 *
 * @author MT-Lin
 */
public class SecurityUser implements UserDetails {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    private String username;
    private String password;
    private String role;

    public SecurityUser(String username, String password, String role) {
        super();
        this.username = username;
        this.password = password;
        this.role = role;
    }

    public SecurityUser() {
    }

    @Override
    public String toString() {
        return "SecurityUser [username=" + username + ", password=" + password + ", role=" + role + "]";
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        Collection<GrantedAuthority> authorities = new ArrayList<>();
        SimpleGrantedAuthority authority = new SimpleGrantedAuthority(this.role);
        authorities.add(authority);
        return authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    /**
     * 账号是否没有过期
     */
    @Override
    public boolean isAccountNonExpired() {
        logger.warn("username[{}] status: isAccountNonExpired->{}", this.getUsername(), true);
        return true;
    }

    /**
     * 账号是不是没有被锁定
     */
    @Override
    public boolean isAccountNonLocked() {
        logger.warn("username[{}] status: isAccountNonLocked->{}", this.getUsername(), true);
        return true;
    }

    /**
     * 证书是不是没有过期
     */
    @Override
    public boolean isCredentialsNonExpired() {
        logger.warn("username[{}] status: isCredentialsNonExpired->{}", this.getUsername(), true);
        return true;
    }

    /**
     * 是不是已经激活
     */
    @Override
    public boolean isEnabled() {
        logger.warn("username[{}] status: isEnabled->{}", this.getUsername(), true);
        return true;
    }

}
